//
//  ZSBarButtonItem.swift
//  新浪微博-Swift
//
//  Created by 周李波 on 16/7/19.
//  Copyright © 2016年 q. All rights reserved.
//

import UIKit

class ZSBarButtonItem: UIBarButtonItem {
    //重载构造函数
    init(title: String? = nil,imageName: String? = nil,target: AnyObject?, action: Selector) {
        super.init()
        let button = UIButton()
        //判断是够有文字
        if let ti = title {
            button.setTitle(ti, forState: UIControlState.Normal)
            button .setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
            button.titleLabel?.font = UIFont.systemFontOfSize(16)
        }
        //判断是否有图片
        if let imgName = imageName {
            button.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        }
        //设置点击事件
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        button.sizeToFit()
        // 赋值
        self.customView = button
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
